package com.lwei.tallybook.client.properties;

import cn.hutool.cache.impl.TimedCache;
import cn.hutool.core.io.resource.ClassPathResource;
import cn.hutool.core.lang.Singleton;
import cn.hutool.setting.Setting;
import lombok.Getter;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * 通用配置文件
 * @author sks.lwei
 */
@Log4j2
@Component
public class GeneralProperties {

    @Value("${general.servlet.cookie.expire-time}")
    private int cookieExpireTime = -1;

    private Setting setting;

    public GeneralProperties() {}

    public Setting getSetting() {
        if(setting == null){
            //获取单例对象
            this.setting = Singleton.get(Setting.class, "properties/GeneralProperties.setting");
            //设置在配置文件变更时自动加载
            this.setting.autoLoad(true);
        }
        return setting;
    }

    public int getCookieExpireTime() {
        log.info("当前cookie过期时间：" + cookieExpireTime);
        return cookieExpireTime;
    }
}
